import { getTopCategoryAPI } from '@/apis/category';
import { onMounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';

export function useCategory() {
    const route = useRoute()
    const categoryData = ref({})
    const getCategoryData = async () => {
        const { data: res } = await getTopCategoryAPI(route.params.id)
        categoryData.value = res.result
    }
    onMounted(() => {
        getCategoryData()
    })
    watch(route, () => {
        getCategoryData()
    })
    return {
        categoryData
    }
}